#!/bin/bash

# 微信订阅消息测试脚本
# 使用方法: ./test-subscribe-message.sh

BASE_URL="http://localhost:8090"
USER_ID=4

echo "🧪 开始测试微信订阅消息功能"
echo "================================"

# 1. 测试发送饮水提醒消息
echo "📱 测试1: 发送饮水提醒消息"
curl -X POST "${BASE_URL}/api/wechat/subscribe/water-reminder" \
  -d "userId=${USER_ID}&waterAmount=800&goalAmount=2000&reminderTime=2025-01-18 15:30:00" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  | jq '.' 2>/dev/null || echo "响应格式不是JSON"

echo -e "\n"

# 2. 测试发送目标达成消息  
echo "📱 测试2: 发送目标达成消息"
curl -X POST "${BASE_URL}/api/wechat/subscribe/goal-achieved" \
  -d "userId=${USER_ID}&goalAmount=2000&actualAmount=2100&achieveDate=2025-01-18" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  | jq '.' 2>/dev/null || echo "响应格式不是JSON"

echo -e "\n"

# 3. 测试发送自定义消息
echo "📱 测试3: 发送自定义消息"
curl -X POST "${BASE_URL}/api/wechat/subscribe/custom?userId=${USER_ID}&page=pages/water/index" \
  -H "Content-Type: application/json" \
  -d '{
    "thing1": "自定义提醒",
    "amount2": "1500ml", 
    "time3": "2025-01-18 16:00:00",
    "thing4": "这是一条测试消息"
  }' | jq '.' 2>/dev/null || echo "响应格式不是JSON"

echo -e "\n"

# 4. 测试快速测试接口
echo "📱 测试4: 快速测试接口"
curl -X POST "${BASE_URL}/api/wechat/subscribe/test?userId=${USER_ID}" \
  | jq '.' 2>/dev/null || echo "响应格式不是JSON"

echo -e "\n================================"
echo "✅ 测试完成！"
echo ""
echo "📋 注意事项:"
echo "1. 确保用户ID=${USER_ID}存在且已绑定微信"
echo "2. 用户需要先在小程序中同意订阅消息"
echo "3. 一次性订阅消息发送后需要重新获取用户同意"
echo "4. 检查后端日志查看详细的发送结果" 